using Circus.CodeEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
namespace Circus.Syntax
{
	[Serializable]
	public class SyntaxNodes : SortList<SyntaxNode>
	{
		public virtual bool PositionChanged(int x, int y, int deltaX, int deltaY, IComparer<SyntaxNode> comparer)
		{
			bool result = false;
			int num;
			if (!base.FindLast(new SyntaxNode(new Point(x, y), string.Empty), out num, comparer))
			{
				num--;
			}
			for (int i = Math.Max(num, 0); i < base.Count; i++)
			{
				SyntaxNode syntaxNode = base[i];
				Range range = syntaxNode.Range;
				Point point = range.StartPoint;
				if (deltaY == 0 && point.Y > y)
				{
					break;
				}
				if (Range.UpdatePos(x, y, deltaX, deltaY, ref point, false))
				{
					range.StartPoint = point;
					result = true;
				}
				point = range.EndPoint;
				if (Range.UpdatePos(x, y, deltaX, deltaY, ref point, true))
				{
					range.EndPoint = point;
					result = true;
				}
				if (syntaxNode.PositionChanged(x, y, deltaX, deltaY, comparer))
				{
					result = true;
				}
			}
			return result;
		}
		public virtual bool BlockDeleting(Rectangle rect, IComparer<SyntaxNode> comparer)
		{
			bool result = false;
			int num;
			if (base.FindLast(new SyntaxNode(new Point(rect.Right, rect.Bottom), string.Empty), out num, comparer))
			{
				num++;
			}
			for (int i = Math.Min(num, base.Count - 1); i >= 0; i--)
			{
				SyntaxNode syntaxNode = base[i];
				Range range = syntaxNode.Range;
				if (range.EndPoint.Y < rect.Top)
				{
					break;
				}
				if (SortList<SyntaxNode>.InsideRange(range.StartPoint, rect) && SortList<SyntaxNode>.InsideRange(new Point(Math.Max(range.EndPoint.X - 1, 0), range.EndPoint.Y), rect))
				{
					base.RemoveAt(i);
					result = true;
				}
				else
				{
					syntaxNode.BlockDeleting(rect, comparer);
				}
			}
			return result;
		}
	}
}
